00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "tinyxml.h"
00026
00027
00028 #ifndef TIXML_USE_STL
00029
00030 #ifndef TIXML_STRING_INCLUDED
00031 #define TIXML_STRING_INCLUDED
00032
00033 #pragma warning( disable : 4514 )
00034
00035 #include <assert.h>
00036
00037
00038
00039
00040
00041
00042
00043
00044 class TiXmlString
00045 {
00046 public :
00047
00048 TiXmlString (const char * instring);
00049
00050
00051 TiXmlString ()
00052 {
00053 allocated = 0;
00054 cstring = NULL;
00055 current_length = 0;
00056 }
00057
00058
00059 TiXmlString (const TiXmlString& copy);
00060
00061
00062 ~ TiXmlString ()
00063 {
00064 empty_it ();
00065 }
00066
00067
00068 const char * c_str () const
00069 {
00070 if (allocated)
00071 return cstring;
00072 return "";
00073 }
00074
00075
00076 unsigned length () const
00077 {
00078 return ( allocated ) ? current_length : 0;
00079 }
00080 unsigned size () const
00081 { return length(); }
00082
00083
00084 void operator = (const char * content);
00085
00086
00087 void operator = (const TiXmlString & copy);
00088
00089
00090 TiXmlString& operator += (const char * suffix)
00091 {
00092 append (suffix);
00093 return *this;
00094 }
00095
00096
00097 TiXmlString& operator += (char single)
00098 {
00099 append (single);
00100 return *this;
00101 }
00102
00103
00104 TiXmlString& operator += (TiXmlString & suffix)
00105 {
00106 append (suffix);
00107 return *this;
00108 }
00109 bool operator == (const TiXmlString & compare) const;
00110 bool operator < (const TiXmlString & compare) const;
00111 bool operator > (const TiXmlString & compare) const;
00112
00113
00114 bool empty () const
00115 {
00116 return length () ? false : true;
00117 }
00118
00119
00120
00121
00122
00123
00124
00125 const char& at (unsigned index) const
00126 {
00127 assert( index < length ());
00128 return cstring [index];
00129 }
00130
00131
00132 unsigned find (char lookup) const
00133 {
00134 return find (lookup, 0);
00135 }
00136
00137
00138 unsigned find (char tofind, unsigned offset) const;
00139
00140
00141
00142
00143 void reserve (unsigned size)
00144 {
00145 empty_it ();
00146 if (size)
00147 {
00148 allocated = size;
00149 cstring = new char [size];
00150 cstring [0] = 0;
00151 current_length = 0;
00152 }
00153 }
00154
00155
00156 char& operator [] (unsigned index) const
00157 {
00158 assert( index < length ());
00159 return cstring [index];
00160 }
00161
00162
00163 enum { notfound = 0xffffffff,
00164 npos = notfound };
00165
00166 void append (const char *str, int len );
00167
00168 protected :
00169
00170
00171 char * cstring;
00172
00173 unsigned allocated;
00174
00175 unsigned current_length;
00176
00177
00178
00179 unsigned assign_new_size (unsigned minimum_to_allocate)
00180 {
00181
00182 for (unsigned pow2 = 2; pow2 < minimum_to_allocate; pow2 *= 2)
00183 {
00184 }
00185 return pow2;
00186 }
00187
00188
00189 void empty_it ()
00190 {
00191 if (cstring)
00192 delete [] cstring;
00193 cstring = NULL;
00194 allocated = 0;
00195 current_length = 0;
00196 }
00197
00198 void append (const char *suffix );
00199
00200
00201 void append (const TiXmlString & suffix)
00202 {
00203 append (suffix . c_str ());
00204 }
00205
00206
00207 void append (char single)
00208 {
00209 char smallstr [2];
00210 smallstr [0] = single;
00211 smallstr [1] = 0;
00212 append (smallstr);
00213 }
00214
00215 } ;
00216
00217
00218
00219
00220
00221 class TiXmlOutStream : public TiXmlString
00222 {
00223 public :
00224 TiXmlOutStream () : TiXmlString () {}
00225
00226
00227 TiXmlOutStream & operator << (const char * in)
00228 {
00229 append (in);
00230 return (* this);
00231 }
00232
00233
00234 TiXmlOutStream & operator << (const TiXmlString & in)
00235 {
00236 append (in . c_str ());
00237 return (* this);
00238 }
00239 } ;
00240
00241 #endif // TIXML_STRING_INCLUDED
00242 #endif // TIXML_USE_STL